const fs = require('fs')
const execa = require('execa')
const targets = fs.readdirSync('packages').filter(f=>{
    if(!fs.statSync(`packages/${f}`).isDirectory()){
        return false
    }
    return  true
})
// 对我们目标进行依次打包，并行打包
async function build(target){
    await execa('rollup', [
        '-c',
        '--environment',
        `TARGET:${target}`
    ],{stdio: 'inherit'})
}
async function runParallel(targets,iteratorFn){

    let arr = []
    targets.forEach(target =>{

       arr.push(iteratorFn(target))
    })
    return Promise.all(arr)
}
runParallel(targets,build)
